package com.fire.control.system.config.filter;
import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* @ClassName: MyFilter
* @Description: TODO(过滤器)
* @author wanbo
* @date 2017年6月19日 上午9:38:21
*/
@WebFilter(filterName="myFilter",urlPatterns="/*")
public class MyFilter implements Filter {
	
	private static final Logger logger = LoggerFactory.getLogger(MyFilter.class);
	
    @Override
    public void destroy() {
    	logger.info("--------->Filter销毁");
    }
    
    @Override
    public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;
        String url = req.getServletPath(); 
        if(!"/favicon.ico".equals(url)){
        	//logger.info("--------->Filter执行过滤操作:"+req.getServletPath());        	
        }
        res.setCharacterEncoding("UTF-8");
        res.addHeader("Access-Control-Allow-Origin", "*");
        res.setHeader("Content-Type", "application/json;charset=UTF-8");
        res.setDateHeader("expires", -1);
		res.setHeader("Cache-Control", "no-cache");
		res.setHeader("Pragma", "no-cache");
        chain.doFilter(request, response);
    }
    
    @Override
    public void init(FilterConfig config) throws ServletException {
    	logger.info("--------->Filter初始化");
    }

}